//
//  Detail_haokaCell.m
//  BMProject
//
//  Created by chris on 16/1/2.
//  Copyright © 2016年 BMProject. All rights reserved.
//

#import "Detail_haokaCell.h"
#import "DataModel.h"

@interface Detail_haokaCell() <UITextFieldDelegate>{

}
@end

@implementation Detail_haokaCell

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)setInfo:(OrderDealDetailOrderContentInfo *)info {
    _info = info;
    self.typeLa.text =  [NSString ignoreEmptyStr:info.secondType];//类别
    self.numLa.text = [NSString ignoreEmptyStr:info.sqAmount];//申请数目
    self.numTF.text = [NSString ignoreEmptyStr:info.sjAmount];//实发数目
    self.tipLa.text = [NSString ignoreEmptyStr:info.remark];//备注
    if (_isCanEdit) {
        self.numTF.enabled = YES;
    } else {
        self.numTF.enabled = NO;
    }
}

#pragma mark UITextFieldDelegate
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
    if (textField == self.numTF) {
        NSString * toBeString = [textField.text stringByReplacingCharactersInRange:range withString:string];
        if (toBeString.length > 20 && range.length!=1){ //最大20个字符
            textField.text = [toBeString substringToIndex:20];
            return NO;
        }
        if ([string chenkInputNSCharacterSetWithType:2])//kNumbers
        {
            return YES;
        }
        else
            return NO;
    }
    return YES;
}

- (void)textFieldDidEndEditing:(UITextField *)textField {
    if (textField == self.numTF) {
        self.info.sjAmount = textField.text;
    }
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        UIImageView * line = [[UIImageView alloc]initWithFrame:CGRectMake1(10, 29, 300, 1)];
        line.backgroundColor = [UIColor colorWithRed:0.69 green:0.78 blue:0.93 alpha:1];

        [self.contentView addSubview:line];
        
        for (int i = 0; i < 5; i++)
        {
            UIImageView * line = [[UIImageView alloc]initWithFrame:CGRectMake1(10+(300/4)*i, 0, 1, 30)];
            line.backgroundColor = [UIColor colorWithRed:0.69 green:0.78 blue:0.93 alpha:1];
            [self.contentView addSubview:line];
        }
        
        _typeLa = [[UILabel alloc]initWithFrame:CGRectMake1(11, 5, 73, 20)];
        _typeLa.backgroundColor = [UIColor whiteColor];
        _typeLa.font = font(13);
        _typeLa.textColor = [UIColor blackColor];
        [self.contentView addSubview:_typeLa];
        
        _numLa = [[UILabel alloc]initWithFrame:CGRectMake1(11+75, 5, 73, 20)];
        _numLa.backgroundColor = [UIColor whiteColor];
        _numLa.font = font(13);
        _numLa.textColor = [UIColor blackColor];
        [self.contentView addSubview:_numLa];
        
        _numTF = [[UITextField alloc]initWithFrame:CGRectMake1(11+75*2, 0, 73, 28)];
        _numTF.backgroundColor = [UIColor whiteColor];
        _numTF.font = font(13);
        self.numTF.delegate = self;
        self.numTF.clearButtonMode = UITextFieldViewModeWhileEditing;
        self.numTF.keyboardType = UIKeyboardTypeNumberPad;
        _numTF.textColor = [UIColor blackColor];
        [self.contentView addSubview:_numTF];
        
        _tipLa = [[UILabel alloc]initWithFrame:CGRectMake1(11+75*3, 5, 73, 20)];
        _tipLa.backgroundColor = [UIColor whiteColor];
        _tipLa.font = font(13);
        _tipLa.textColor = [UIColor blackColor];
        [self.contentView addSubview:_tipLa];
    }
    return self;
}

CG_INLINE CGRect
CGRectMake1(CGFloat x, CGFloat y, CGFloat width, CGFloat height)
{
    CGRect rect;
    rect.origin.x = x*ratio_width; rect.origin.y = y*ratio_heigth;
    rect.size.width = width*ratio_width; rect.size.height = height*ratio_heigth;
    return rect;
}

@end
